import 'dart:convert';
import 'package:crypto/crypto.dart';
import '../../../utils/common/app_manager.dart';
import '../../../utils/networking/http_manager.dart';
export '../../../utils/networking/http_manager.dart';
import '../../../utils/umemg_manager/umeng_manager.dart';

class UserRequest {
  
  /// 获取 userToken
  static Future<ResponseAnalyzed> getUserToken(var uuid) async {
    String url = "";
    final param = {"uuid": uuid};
    return await HttpManager.requestAnalyzing(HttpMethod.post, url, params: param);
  }

  /// 发送验证码
  static Future<ResponseAnalyzed> shortMessageCode(var value) async {
    String url = "";
    final param = {"": ""};
    return await HttpManager.requestAnalyzing(HttpMethod.post, url, params: param);
  }

  /// 注册
  static Future<ResponseAnalyzed> registerAccount(var value) async {
    String url = "";
    final param = {"": ""};
    return await HttpManager.requestAnalyzing(HttpMethod.post, url, params: param);
  }

  /// 短信登录
  static Future<ResponseAnalyzed> loginWithShortMessage(var value) async {
    String url = "";
    final param = {"": ""};
    return await HttpManager.requestAnalyzing(HttpMethod.post, url, params: param);
  }

  /// 密码登录
  // static Future<ResponseAnalyzed> loginWithPassword({required String account, required String password}) async {
  //   String url = "";
  //   final param = {"account": "", "password": ""};
  //   return await HttpManager.requestAnalyzing(HttpMethod.post, url, params: param);
  // }

  // 密码登录
  static Future<ResponseAnalyzed> loginWithPassword({String account = "", String password = ''}) async {
    var account1 = account.replaceAll(" ", ""); // 如果有中文空格自动去除
    var account2 = account1.replaceAll(" ", ""); // 如果是英文空格自动去除
    String url = "/pub/v1/tenement/appLogin";

    final wdm5 = md5.convert(utf8.encode(password));
    final wdm5base64 = base64Encode(utf8.encode(wdm5.toString()));
    var deviceToken = await AppManager.getDeviceToken();
    final data = {
      "inputBox": account2,
      "password": wdm5base64,
      //"uuid": AppManager.uuid,// 不可以使用，否则在调用首页接口时会返回 20401 退出登录。
      "deviceToken": deviceToken ?? await AppManager.getDeviceToken(),
    };
    return await HttpManager.requestAnalyzing(HttpMethod.post, url, params: data);
  }


  /// 忘记密码
  static Future<ResponseAnalyzed> forgetPassword(var value) async {
    String url = "";
    final param = {"": ""};
    return await HttpManager.requestAnalyzing(HttpMethod.post, url, params: param);
  }

  /// 退出登录
  static Future<ResponseAnalyzed> logout(var value) async {
    String url = "";
    final param = {"": ""};
    return await HttpManager.requestAnalyzing(HttpMethod.post, url, params: param);
  }

  /// 上报用户同意隐私协议
  static Future<ResponseAnalyzed> uploadingSigned(var uuid) async {
    String url = "";
    final param = {"uuid": ""};
    return await HttpManager.requestAnalyzing(HttpMethod.post, url, params: param);
  }


}